<%-- 
    Document   : ccvs
    Created on : Dec 13, 2009, 6:39:38 PM
    Author     : Jeremy
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.List" %>
<%@ page import="jhu.profiteer.data.Location" %>
<%@ page import="jhu.profiteer.data.LocationJpaController" %>
<%@ page import="jhu.profiteer.data.Character" %>
<%@ page import="jhu.profiteer.data.CharacterJpaController" %>
<%@ page import="jhu.profiteer.data.Commodity" %>
<%@ page import="jhu.profiteer.data.CommodityJpaController" %>
<%@ page import="jhu.profiteer.data.CurrentCommodityValue" %>
<%@ page import="jhu.profiteer.data.CurrentCommodityValueJpaController" %>

<%@ include file="/WEB-INF/jspf/admin/auth.jspf" %>
<html>
  <%
    String pageTitle = "Administration Homepage - Current Commodity Values";
    String cssFile = "/profiteer-game/css/profiteer.css";
  %>
  <%@ include file="/WEB-INF/jspf/admin/header.jspf" %>
  <body>
    <%@ include file="/WEB-INF/jspf/title.jspf" %>
    <div class="contentArea Body">
      <div class="pagetitle">Administration</div>
      <div class="pagebody">
        <table>
          <tr>
            <td id="menu"><%@ include file="/WEB-INF/jspf/admin/sidebar.jspf" %></td>
            <td>
              <div class="divround">
                <%@ include file="/WEB-INF/jspf/admin/notice.jspf" %>
                <%
                  notices = (Vector<String>)session.getAttribute("notices");
                  LocationJpaController ljc = new LocationJpaController();
                  String locIdParam = request.getParameter("locationId");

                  if((null == locIdParam) || locIdParam.isEmpty())
                  {
                    if(null == notices) notices = new Vector<String>();
                    notices.add("You must supply a location ID.");
                    session.setAttribute("notices", notices);
                    this.getServletContext()
                            .getRequestDispatcher("/ccvs")
                            .forward(request, response);
                  }

                  Location l = ljc.findLocation(Long.parseLong(locIdParam));
                  CharacterJpaController cjc = new CharacterJpaController();
                  String charIdParam = request.getParameter("characterId");

                  if((null == charIdParam) || charIdParam.isEmpty())
                  {
                    if(null == notices) notices = new Vector<String>();
                    notices.add("You must supply a character ID.");
                    session.setAttribute("notices", notices);
                    this.getServletContext()
                            .getRequestDispatcher("/ccvs")
                            .forward(request, response);
                  }

                  CommodityJpaController comjc = new CommodityJpaController();
                  Long charId = Long.parseLong(charIdParam);
                  Character c = cjc.findCharacter(charId);
                %>
                <table>
                  <tr>
                    <td>Character:</td>
                    <td><%= c.getName() %></td>
                  </tr>
                  <tr>
                    <td>Location:</td>
                    <td><%= l.getName() %></td>
                  </tr>
                </table>
                <%
                  CurrentCommodityValueJpaController ccvjc =
                          new CurrentCommodityValueJpaController();
                  List<CurrentCommodityValue> ccvs = ccvjc
                          .findCurrentCommodityValuesByCharacterId(charId);

                  if(0 == ccvs.size())
                  {
                %>
                  <p>There are no current commodity values available!</p>
                <%
                  }
                  else
                  {
                %>
                  <table>
                    <tr>
                      <th id="left">Commodity</th>
                      <th id="left">Price</th>
                    </tr>
                    <%
                      for(CurrentCommodityValue ccv : ccvs)
                      {
                        Commodity com = comjc.findCommodity(ccv
                                .getId()
                                .getCommodityId());
                    %>
                    <tr>
                      <td><%= com.getName() %></td>
                      <td><%= ccv.getPrice() %></td>
                    </tr>
                    <%
                      }
                    %>
                  </table>
                <%
                  }
                %>
              </div>
            </td>
          </tr>
        </table>
      </div>
    </div>
    <%@ include file="/WEB-INF/jspf/footer.jspf" %>
  </body>
</html>
